package com.fram.service.api.v1.android.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.exception.ProValiDataException;
import com.fram.common.util.base.BaseService;
import com.fram.common.util.qiniu.QiniuUtils;
import com.fram.entity.DistributorFarm;
import com.fram.mapper.DistributorFarmMapper;
import com.fram.service.api.v1.android.DistributorAndroidService;

@Service
public class DistributorAndroidServiceImpl extends BaseService implements DistributorAndroidService{
	
	@Autowired
	private DistributorFarmMapper distributorFarmMapper;
	@Autowired
	private QiniuUtils qiniuUtils;
	@Override
	public DistributorFarm detail(Long id) throws ProException {
		DistributorFarm distributorFarm= distributorFarmMapper.selectByPrimaryKey(id);
		if(distributorFarm == null) {
			throw new ProValiDataException(ErrCode.NO_DATA.getReturnCode(), ErrCode.NO_DATA.getReturnMsg());
		}
		return distributorFarm;
	}

	@Override
	public void update(DistributorFarm request) throws ProException {
		request.setLogo(qiniuUtils.uploadImageUrl(request.getLogo()));
		if(distributorFarmMapper.updateByPrimaryKeySelective(request)<=0) {
			throw new ProValiDataException(ErrCode.FAIL.getReturnCode(), ErrCode.FAIL.getReturnMsg());
		}
	}
	
}
